package com.zzh.lib.core.listener;

import android.view.View;

import com.zzh.lib.core.utils.HKeyboardUtils;

/**
 * Created by ZZH on 2021/7/23.
 *
 * @Date: 2021/7/23
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description: 点击事件处理，1、禁止频繁点击，2、点击的时候将软键盘隐藏
 */
public abstract class HOnClickListener implements View.OnClickListener {
    protected long interval = 300L;
    private long lastClickTime = 0l;

    @Override
    public void onClick(View v) {
        if ((System.currentTimeMillis() - lastClickTime) > interval) {
            HKeyboardUtils.closeKeyboard(v);
            onSafeClick(v);
        } else {
            onIntervalClick(v);
        }
        lastClickTime = System.currentTimeMillis();
    }

    /**
     * 点击事件处理
     *
     * @param v 点击的View
     */
    public abstract void onSafeClick(View v);

    /**
     * 间隔内点击事件
     *
     * @param v
     */
    public void onIntervalClick(View v) {

    }
}
